from PyQt5.QtWidgets import *


class ProxySettingsForm(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 使用代理的单选开关
        self.useProxyRadioButton = QRadioButton('关闭')
        self.useProxyRadioButton.setChecked(True)  # 默认关闭
        self.useProxyRadioButton.toggled.connect(self.toggleProxySettings)

        self.enableProxyRadioButton = QRadioButton('开启')

        # 地址输入框
        self.proxyAddressLineEdit = QLineEdit()

        # 端口输入框
        self.proxyPortLineEdit = QLineEdit()

        # 更多按钮
        self.moreButton = QPushButton('更多')
        self.moreButton.clicked.connect(self.showMoreSettings)

        # 账户输入框
        self.proxyAccountLineEdit = QLineEdit()

        # 密码输入框
        self.proxyPasswordLineEdit = QLineEdit()
        self.proxyPasswordLineEdit.setEchoMode(QLineEdit.Password)

        layout = QVBoxLayout()
        layout.addWidget(self.useProxyRadioButton)
        layout.addWidget(self.enableProxyRadioButton)
        layout.addWidget(QLabel('地址:'))
        layout.addWidget(self.proxyAddressLineEdit)
        layout.addWidget(QLabel('端口:'))
        layout.addWidget(self.proxyPortLineEdit)
        layout.addWidget(self.moreButton)
        layout.addWidget(QLabel('账户:'))
        layout.addWidget(self.proxyAccountLineEdit)
        layout.addWidget(QLabel('密码:'))
        layout.addWidget(self.proxyPasswordLineEdit)

        self.setLayout(layout)

    def toggleProxySettings(self, checked):
        if checked:
            self.proxyAddressLineEdit.setEnabled(True)
            self.proxyPortLineEdit.setEnabled(True)
            self.moreButton.setEnabled(True)
        else:
            self.proxyAddressLineEdit.setEnabled(False)
            self.proxyPortLineEdit.setEnabled(False)
            self.moreButton.setEnabled(False)

    def showMoreSettings(self):
        # 在此处添加更多设置的展示逻辑
        print("更多设置被点击")
